package com.wehgu.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wehgu.admin.common.vo.UserInfoVO;
import com.wehgu.admin.entities.SysRole;
import com.wehgu.admin.entities.SysUser;
import com.wehgu.admin.entities.dto.UserPageQuery;
import com.wehgu.admin.mapper.SysUserMapper;
import com.wehgu.admin.service.ISysUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author generate by isMiao
 * @since 2022-03-05
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {

    @Resource
    SysUserMapper sysUserMapper;

    @Resource
    SysRoleServiceImpl sysRoleService;


    @Override
    public List<UserInfoVO> selectUsers(Page<UserInfoVO> page, UserPageQuery input) {

        if(input.getRoleName()!=null){
            SysRole role=sysRoleService.getOne(new QueryWrapper<SysRole>()
            .eq("role_name",input.getRoleName()));
            if(role==null){
                input.setRoleUID("");
            }else {
                input.setRoleUID(role.getRoleUuid());
            }

        }

        //获取部门
        if(input.getRoleName()!=null){

            input.setDeptUID("");
        }

        return sysUserMapper.selectUsers(page,input);
    }
}
